import java.util.Arrays;

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = 0;
        int j = 0;
        int count = 0;
        int[] arr = Arrays.copyOf(nums1,m);
        while(m > 0 && n > 0) {
            if(arr[i] <= nums2[j]) {
                nums1[count] = arr[i];
                m--;
                count++;
                i++;
            } else {
                nums1[count] = nums2[j];
                n--;
                count++;
                j++;
            }
        }
        while(m != 0) {
            nums1[count++] = arr[i++];
            m--;
        }
        while(n != 0) {
            nums1[count++] = nums2[j++];
            n--;
        }
    }
    public int removeDuplicates(int[] nums) {
        int c = 0;
        for(int i = 0; i < nums.length;i ++) {
            if(nums[c] != nums[i]) {
                c++;
                nums[c] = nums[i];
            }
        }
        return c;
    }
    public int removeDuplicates1(int[] nums) {
        int n = nums.length;
        if (n <= 2) {
            return n;
        }
        int slow = 2, fast = 2;
        while (fast < n) {
            if (nums[slow - 2] != nums[fast]) {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }
}